//
//  NYRemovedViewModel.m
//  Nooryes
//
//  Created by baken on 2020/2/25.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYRemovedViewModel.h"
#import "NYRemovedManager.h"
#import "NYArticleListModel.h"
#import "NYInfluenceManager.h"
#import "NYCategoryModel.h"

@implementation NYRemovedViewModel

-(void)getRemovedCategoryWithCompletionHandle:(CompletionHandle)complete{
    [NYInfluenceManager getCategoryWithType:self.type andCompletionHandle:^(NYCategoryModel * _Nonnull model, NSError * _Nonnull error) {
        if (!error) {
            [self.topicArray addObjectsFromArray:model.data];
        }
        complete(error);
    }];
}

-(void)refreshDataCompletionHandle:(CompletionHandle)completionHandle{
    self.pageNum = 1;
    [self getRemovedListWithCompletionHandle:completionHandle];
}

-(void)getMoreDataCompletionHandle:(CompletionHandle)completionHandle{
    self.pageNum++;
    [self getRemovedListWithCompletionHandle:completionHandle];
}


- (void)getRemovedListWithCompletionHandle:(CompletionHandle)complete{
    [NYRemovedManager getRemovedListWithPage:STR_FROM_INT(self.pageNum) andTopicID:self.topicID andCompletionHandle:^(NYArticleListModel *model, NSError * _Nonnull error) {
        if (!error) {
            if (self.pageNum == 1) {
                [self.dataArr removeAllObjects];
            }
            
            [self.dataArr addObjectsFromArray:model.data];
        }
        complete(error);
    }];
}

-(NSMutableArray *)topicArray{
    if (!_topicArray) {
        _topicArray = [NSMutableArray array];
    }
    return _topicArray;
}

@end
